﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.effects {
    import Classes.*;
    import com.greensock.*;
    import com.greensock.easing.*;

    public class SimpleBounceEffect extends MapResourceEffect {

        private const SHAKE_WIDTH:Number = 5;
        private const BOUNCE_HEIGHT:Number = 75;

        private var m_isAnimationComplete:Boolean = false;
        private var m_originalX:Number;
        private var m_originalY:Number;
        private var m_animTimeline:TimelineLite;

        public function SimpleBounceEffect(_arg1:MapResource){
            super(_arg1);
            this.animate(1);
        }
        override public function animate(_arg1:uint):Boolean{
            if (this.m_isAnimationComplete){
                return (false);
            };
            if (isMapResourceLoaded){
                this.startBounce();
                this.m_isAnimationComplete = true;
                return (false);
            };
            return (true);
        }
        override public function cleanUp():void{
            if (this.m_animTimeline){
                this.m_animTimeline.kill();
            };
            if (this.m_isAnimationComplete){
                m_mapResource.content.x = this.m_originalX;
                m_mapResource.content.y = this.m_originalY;
            } else {
                this.m_isAnimationComplete = true;
            };
            m_isCompleted = true;
        }
        private function startBounce():void{
            this.m_originalX = m_mapResource.content.x;
            this.m_originalY = m_mapResource.content.y;
            var _local1:Number = this.SHAKE_WIDTH;
            var _local2:Number = this.BOUNCE_HEIGHT;
            this.m_animTimeline = new TimelineLite({onComplete:this.bounceCompleteHandler});
            this.m_animTimeline.appendMultiple([new TweenLite(m_mapResource.content, 0.25, {
                y:(this.m_originalY - _local2),
                ease:Quad.easeOut
            }), new TweenLite(m_mapResource.content, 0.25, {
                y:this.m_originalY,
                ease:Quad.easeIn
            }), new TweenLite(m_mapResource.content, 0.12, {
                y:(this.m_originalY - (_local2 * 0.25)),
                ease:Quad.easeOut
            }), new TweenLite(m_mapResource.content, 0.12, {
                y:this.m_originalY,
                ease:Quad.easeIn
            })], 0, TweenAlign.SEQUENCE);
        }
        private function bounceCompleteHandler():void{
            this.cleanUp();
        }

    }
}//package Classes.effects 
